//
//  ZZDetailCommentCell.m
//  QQplayground
//
//  Created by zhangxy on 2018/6/20.
//  Copyright © 2018年 zhang. All rights reserved.
//

#import "ZZDetailCommentCell.h"

#import <SDWebImage/UIImageView+WebCache.h>

#import "ZZContentCommentController.h"
#import "ZCTTMLEmojiLabel.h"
#import "SVWebViewController.h"
#import "UserInfoController.h"
#import "MWPhotoBrowser.h"

@interface ZZDetailCommentCell()<ZCTTMLEmojiLabelDelegate,UIGestureRecognizerDelegate>{
    NSString    *callURL;
    
    NSString * morelink;
}

@end

@implementation ZZDetailCommentCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    _imgAvatar.layer.cornerRadius = 22.0f;
    _imgAvatar.layer.masksToBounds = YES;
    
    [_labTitle setFont:FontFiftent];
    _labTitle.numberOfLines = 0;
    [_labTitle setTextColor:UIColorFromRGB(TextSizeOneColor)];
    [_labTitle setLinkColor:UIColorFromRGB(TextLinkColor)];
    [_labTitle setDelegate:self];
    [_labTitle setText:@""];
    
    [_labName setFont:FontFiftent];
    [_labName setTextColor:UIColorFromRGB(TextSizeOneColor)];
    
    [_btnLevel.titleLabel setFont:ListElevenFont];
    _btnLevel.layer.cornerRadius = 4.0f;
    _btnLevel.layer.masksToBounds = YES;
    //_btnLevel.layer.borderWidth = 1.0f;
    //_btnLevel.layer.borderColor = UIColorFromRGB(BorderLineColor).CGColor;
    [_btnLevel setTitleColor:UIColorFromRGB(TextSizeOneColor) forState:0];
    //[_btnLevel setImage:[UIImage imageNamed:@"收藏 小按钮"] forState:0];
    
    
    [_labTime setFont:FontThirteen];
    [_labTime setTextColor:UIColorFromRGB(BgLineColor)];
    
    //[self setBtnStype:_btnVip image:@"Combined_Shape"];
    
    _commentView.backgroundColor = UIColorFromRGB(BgSystemColor);
    _commentView.layer.cornerRadius = 3.0f;
    _commentView.layer.masksToBounds = YES;
    
    _imgContent.userInteractionEnabled = YES;
    _imgContent.layer.cornerRadius = 5.0f;
    _imgContent.layer.masksToBounds = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
    [tap addTarget:self action:@selector(imgTouchUpInside:)];
    [_imgContent addGestureRecognizer:tap];
}

-(void)setBtnStype:(UIButton *) btn image:(NSString *)imgName{
    [btn setImage:[UIImage imageNamed:imgName] forState:0];
    [btn setTitleColor:UIColorFromRGB(TextSizeOneColor) forState:0];
    [btn.titleLabel setFont:ListElevenFont];
    [btn setTitle:@"" forState:0];
    [btn setTitleEdgeInsets:UIEdgeInsetsMake(0, 2, 0, 0)];
    [btn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [btn setBackgroundColor:UIColor.clearColor];
}


-(void) moreComment:(UITapGestureRecognizer *) tap{
    if(self.delegate && [self.delegate respondsToSelector:@selector(onCellItemClick:obj:)]){
        [self.delegate onCellItemClick:ZZClickMore obj:self.tempModel];
//        ZZContentCommentController *vc = [[ZZContentCommentController alloc] init];
//        vc.entity = _tempModel;
//        vc.nav_type = convertToString(_nav_type);
//
//        [self.delegate onCellItemClick:ZZClickOpenVC obj:vc];
    }
}


-(void)dataToView:(ZZTopicCommentEntity *) topic{
    _tempModel = topic;
    self.backgroundColor = [UIColor whiteColor];
    [self setUserViewData:topic];
    
    self.frame = CGRectMake(0, 0, ScreenWidth, CGRectGetMaxY(_commentView.frame)+20);
    
    
//    NSLog(@"\n========\n%@\n%@\ncell:%@\ncomment:%@\n",topic.user_info.user_name,topic.message,NSStringFromCGRect(self.frame),NSStringFromCGRect(_commentView.frame));
}

-(void)drawRect:(CGRect)rect{
    [super drawRect:rect];
    CGRect lf = _btnLevel.frame;
    lf.origin.x = CGRectGetMaxX(_labName.frame) + 5;
    _btnLevel.frame = lf;
    
    
    [_btnVip setFrame:CGRectMake(CGRectGetMaxX(lf) + 5, lf.origin.y, 52, 18)];
    
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    [self.contentView layoutIfNeeded];
//    self.frame = CGRectMake(0, 0, ScreenWidth, CGRectGetMaxY(_commentView.frame)+20);
    
}

-(void)setUserViewData:(ZZTopicCommentEntity *) topic{
    [_imgAvatar sd_setImageWithURL:[NSURL URLWithString:convertToString(topic.user_info.user_avatar)] placeholderImage:[UIImage imageNamed:@"default_image"]];
    
    _imgAvatar.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(avatarClick:)];
    [_imgAvatar addGestureRecognizer:tap1];
    
    _labName.userInteractionEnabled = YES;
    [_labName setText:convertToString(topic.user_info.user_name)];
    [_labName sizeToFit];
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(avatarClick:)];
    [_labName addGestureRecognizer:tap2];
    
    CGRect lf = _btnLevel.frame;
    CGSize s = [self autoWidthOfLabel:_labName with:21];
    lf.origin.x = s.width + CGRectGetMaxX(_labName.frame) + 5;
    _btnLevel.frame = lf;
    [self setBtnLevelColor:topic];
    [_btnLevel setContentEdgeInsets:UIEdgeInsetsMake(2, 0, 2, 0)];
    [_btnVip setFrame:CGRectMake(CGRectGetMaxX(lf) + 5, lf.origin.y, 52, 18)];
    if ([topic.user_info.is_vip isEqualToString:@"1"]){
        _btnVip.hidden = NO;
        [_btnVip setImage:[UIImage imageNamed:@"vip"] forState:0];
        [_labName setTextColor:[UIColor colorWithHexString:@"#FF70A6" alpha:1.0]];
    } else {
        _btnVip.hidden = YES;
        [_labName setTextColor:UIColorFromRGB(TextSizeOneColor)];
    }
    [_labTime setText:topic.add_time];
    
    CGFloat iy =  60;
    if(convertToString(topic.message).length == 0){
        _labTitle.hidden = YES;
        iy = 60+(topic.thread_list.count == 0 ? 0 : 10);
    }else{
        _labTitle.hidden = NO;
        
#warning - 显示HTML文本在label
        NSMutableAttributedString *labTitle = [[NSMutableAttributedString alloc] initWithData:[topic.message dataUsingEncoding:NSUnicodeStringEncoding]
                                                                                      options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType}
                                                                           documentAttributes:nil
                                                                                        error:nil];
        [labTitle addAttribute:NSFontAttributeName value:FontFiftent range:NSMakeRange(0, labTitle.length)];
        [labTitle addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(TextSizeOneColor) range:NSMakeRange(0, labTitle.length)];
        _labTitle.attributedText = labTitle;
//         [self addLinkMessage:_labTitle text:topic.message len:nil];
        [self autoWidthOfLabelHegith:_labTitle with:ScreenWidth - 40];
        iy = CGRectGetMaxY(_labTitle.frame)+(topic.thread_list.count == 0 ? 0 : 10);
    }
    
    if(topic.message_image.count > 0){
        _imgContent.hidden = NO;
        ImageEntity *firstObj = [topic.message_image firstObject];
        [_imgContent sd_setImageWithURL:[NSURL URLWithString:firstObj.image_url] placeholderImage:[UIImage imageNamed:@"default_image"]];
        CGRect imgF = _imgContent.frame;
        imgF.origin.y = iy;
        [_imgContent setFrame:imgF];
        iy = iy + 75;
    }else{
        _imgContent.hidden = YES;
    }
    [self addCommentView:topic.thread_list fy:iy];
}
//点击头像去主页
-(void)avatarClick:(UITapGestureRecognizer *) tap{
    UserInfoController *vc = [[UserInfoController alloc] init];
    vc.user_id = _tempModel.user_info.user_id;
    if(_delegate && [self.delegate respondsToSelector:@selector(onCellItemClick:obj:)]){
        [self.delegate onCellItemClick:ZZClickOpenVC obj:vc];
    }
}

-(UIImageView *)createImageView{
    UIImageView *imgView = [[UIImageView alloc] init];
    [imgView setContentMode:UIViewContentModeScaleAspectFill];
    imgView.clipsToBounds = YES;
    return imgView;
}

-(UILabel *) createLabel{
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
    [label setTextAlignment:NSTextAlignmentLeft];
    [label setFont:FontThirteen];
    [label setTextColor:UIColorFromRGB(TextSizeOneColor)];
    [label setBackgroundColor:UIColor.clearColor];
    [label setNumberOfLines:0];
    return label;
}

-(void)addCommentView:(NSMutableArray *) array fy:(CGFloat) fromY{
    [_commentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    CGFloat commentH = 10;
    if(array.count == 0){
        commentH = 0;
    }
    CGFloat maxWidth = ScreenWidth - 66-20;
    for (ZZTopicCommentEntity *entity in array) {
        ZCTTMLEmojiLabel *label = [self createLinkLabel:commentH w:maxWidth];
        
        NSString *text = [NSString stringWithFormat:@"<a href=\"name://\">%@:</a>%@",entity.user_info.user_name,entity.message];
        [self addLinkMessage:label text:text len:entity.user_info];
        
        CGSize s = [self autoWidthOfLabelHegith:label with:label.frame.size.width];
        
        commentH = s.height + commentH + 7;
        [_commentView addSubview:label];
    }
    
    if(array.count < self.tempModel.count){
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, commentH, maxWidth, 21)];
        [label setTextAlignment:NSTextAlignmentLeft];
        [label setFont:FontThirteen];
        [label setTextColor:UIColorFromRGB(Text6Color)];
        [label setBackgroundColor:UIColor.clearColor];
        [label setText:[NSString stringWithFormat:@"查看%zd条回复",self.tempModel.count - self.tempModel.thread_list.count]];
        label.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(moreComment:)];
        [label addGestureRecognizer:tap];
        [_commentView addSubview:label];
        commentH = commentH + 21 + 10;
    }
    
    [_commentView setFrame:CGRectMake(66, fromY, ScreenWidth - 66-20, commentH)];
    
}



/**
 计算Label高度
 
 @param label 要计算的label，设置了值
 @param width label的最大宽度
 */
- (CGSize )autoWidthOfLabel:(UILabel *)label with:(CGFloat )height{
    //Calculate the expected size based on the font and linebreak mode of your label
    // FLT_MAX here simply means no constraint in height
    CGSize maximumLabelSize = CGSizeMake(FLT_MAX, height);
    
    CGSize expectedLabelSize = [label sizeThatFits:maximumLabelSize];
    
    //adjust the label the the new height.
    CGRect newFrame = label.frame;
    newFrame.size.width = expectedLabelSize.width;
    label.frame = newFrame;
    [label updateConstraintsIfNeeded];
    
    return expectedLabelSize;
}

- (CGSize )autoWidthOfLabelHegith:(UILabel *)label with:(CGFloat )width{
    //Calculate the expected size based on the font and linebreak mode of your label
    // FLT_MAX here simply means no constraint in height
    CGSize maximumLabelSize = CGSizeMake(width, FLT_MAX);
    
    CGSize expectedLabelSize = [label sizeThatFits:maximumLabelSize];
    
    //adjust the label the the new height.
    CGRect newFrame = label.frame;
    newFrame.size.height = expectedLabelSize.height;
    label.frame = newFrame;
    [label updateConstraintsIfNeeded];
    
    return expectedLabelSize;
}




#pragma mark - gesture delegate
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if ([NSStringFromClass([touch.view class]) isEqualToString:@"ZCTTMLEmojiLabel"]) {
        return NO;
    }
    return YES;
    
}

-(ZCTTMLEmojiLabel *)createLinkLabel:(CGFloat) y w:(CGFloat ) maxWidth{
    ZCTTMLEmojiLabel *label = [[ZCTTMLEmojiLabel alloc] initWithFrame:CGRectMake(10, y, maxWidth, 0)];
    [label setTextAlignment:NSTextAlignmentLeft];
    label.numberOfLines = 0;
    [label setFont:FontThirteen];
    [label setTextColor:UIColorFromRGB(TextSizeOneColor)];
    [label setBackgroundColor:UIColor.clearColor];
    [label setLinkColor:UIColorFromRGB(TextLinkColor)];
    [label setDelegate:self];
    label.userInteractionEnabled = YES;
    
    return label;
}


-(void)addLinkMessage:(ZCTTMLEmojiLabel *) label text:(NSString *)text len:(User *) user{
    
    text = [ZZCoreTools filterSpecialHTML:text];
    NSString *sugguestText = [ZZCoreTools transformString:text];
    NSMutableDictionary *sugguestDict = [label getTextADict:sugguestText];
    UIColor *color = UIColorFromRGB(Text6Color);
    if([user.is_vip intValue] == 1){
        color = UIColorFromRGB(BgTitleColor);
    }
    if(sugguestDict){
        if(user != nil){
            [label setText:sugguestDict[@"text"] afterInheritingLabelAttributesAndConfiguringWithBlock:^NSMutableAttributedString *(NSMutableAttributedString *mutableAttributedString) {
                //文字颜色
                [mutableAttributedString addAttribute:(NSString *)kCTForegroundColorAttributeName
                                                value:color
                                                range:NSMakeRange(0, convertToString(user.user_name).length + 1)];
                return mutableAttributedString;
            }];
        }else{
            label.text = sugguestDict[@"text"];
        }
        NSArray *sugguestArr = sugguestDict[@"arr"];
        //    [_emojiLabel setText:tempText];
        for (NSDictionary *item in sugguestArr) {
            NSString *text = item[@"htmlText"];
            int loc = [item[@"realFromIndex"] intValue];
            // 一定要在设置text文本之后设置
            [label addLinkToURL:[NSURL URLWithString:item[@"url"]] withRange:NSMakeRange(loc, text.length)];
        }
    }else{
        if(convertToString(text).length > 0 && user!=nil){
            NSMutableAttributedString *mutableAttributedString = [[NSMutableAttributedString alloc] initWithString:text];
            //文字颜色
            [mutableAttributedString addAttribute:(NSString *)kCTForegroundColorAttributeName
                                            value:color
                                            range:NSMakeRange(0, convertToString(user.user_name).length + 1)];
            [label setAttributedText:mutableAttributedString];
        }else{
            label.text = text;
        }
    }
}

// 链接点击
-(void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithURL:(NSURL *)url{
    DLog(@"链接地址:%@",url.absoluteString);
    [self doLinkClick:url.absoluteString];
    
}

// 链接点击
-(void)ZCMLEmojiLabel:(ZCTTMLEmojiLabel *)emojiLabel didSelectLink:(NSString *)link withType:(ZCTTMLEmojiLabelLinkType)type{
    DLog(@"意外添加的：%@",link);
    [self doLinkClick:link];
}


-(void)doLinkClick:(NSString *) url{
    if([url hasPrefix:@"name://"]){
        return;
    }
    if([url hasPrefix:@"uid://"]){
        UserInfoController *vc = [[UserInfoController alloc] init];
        vc.user_id = [url stringByReplacingOccurrencesOfString:@"uid://" withString:@""];
        if(self.delegate && [self.delegate respondsToSelector:@selector(onCellItemClick:obj:)]){
            [self.delegate onCellItemClick:ZZClickOpenVC obj:vc];
        }
    }else{
        if([url hasPrefix:@"tel:"] || validateNumber(url)){
            NSString *callURL = [url stringByReplacingOccurrencesOfString:@"tel:" withString:@""];
            [[AlertUtil shareInstance] showAlert:nil message:callURL cancelTitle:@"取消" titleArray:@[@"呼叫"] viewController:(UIViewController *)self.delegate confirm:^(NSInteger buttonTag) {
                if(buttonTag == 0){
                    // 打电话
                    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callURL]];
                }
            }];
        }else if([url hasPrefix:@"mailto:"] || validateEmail(url)){
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
        }else{
            if (![url hasPrefix:@"https"] && ![url hasPrefix:@"http"]) {
                url = [@"https://" stringByAppendingString:url];
            }
            
            SVWebViewController *vc = [[SVWebViewController alloc] initWithURL:[NSURL URLWithString:url]];
            if(self.delegate && [self.delegate respondsToSelector:@selector(onCellItemClick:obj:)]){
                [self.delegate onCellItemClick:ZZClickOpenVC obj:vc];
            }
        }
    }
    
}





/**
 *  点击查看大图
 *
 *  @param
 */
-(void) imgTouchUpInside:(UITapGestureRecognizer *)recognizer{
    DLog(@"我怎么不处罚呢：");
    UIImageView *_picView = (UIImageView*)recognizer.view;
    NSMutableArray *photos = [NSMutableArray new];
    for (int i = 0;i<self.tempModel.message_image.count; i ++ ) {
        ImageEntity *firstObj = self.tempModel.message_image[i];
        
        MWPhoto *photo = [MWPhoto photoWithURL:[NSURL URLWithString:firstObj.origin_image]];
        
        [photos addObject:photo];
    }
    
    MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithPhotos:photos];
    [browser setCurrentPhotoIndex:_picView.tag];
    browser.zoomPhotosToFill = YES;
    browser.displayNavArrows = NO;
    browser.navigationController.navigationBarHidden = YES;
    browser.displayActionButton = NO;
    //    browser.enableSwipeToDismiss = YES;
    if(_delegate && [self.delegate respondsToSelector:@selector(onCellItemClick:obj:)]){
        [self.delegate onCellItemClick:ZZClickOpenVC obj:browser];
    }
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
//用户等级数的显示问题
-(void)setBtnLevelColor:(ZZTopicCommentEntity *) topic {
    int level = [topic.user_info.group_icon intValue];
    if (level >= 100){
        CGRect lf = _btnLevel.frame;
        lf.size.width = 75;
        _btnLevel.frame = lf;
        [_btnVip setFrame:CGRectMake(CGRectGetMaxX(lf) + 5, lf.origin.y - 2, 52, 18)];
        if (level == 100){
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"10"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch] forState:0];
            [_btnLevel setImage:[UIImage imageNamed:@"荣誉会员"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@"荣誉会员"] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#FFA52A" alpha:1.0] forState:0];
        } else if (level == 101){
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"10"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch] forState:0];
            [_btnLevel setImage:[UIImage imageNamed:@"官方团队"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@"官方团队"] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#FFA52A" alpha:1.0] forState:0];
        } else if (level == 403){
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"1"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch] forState:0];
            [_btnLevel setImage:[UIImage imageNamed:@"系统屏蔽"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@"系统屏蔽"] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#A4A4A4" alpha:1.0] forState:0];
        } else if (level == 102){
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"10"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch] forState:0];
            [_btnLevel setImage:[UIImage imageNamed:@"小组长"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@"小组长"] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#FFA52A" alpha:1.0] forState:0];
        } else if (level == 200){
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"4"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch] forState:0];
            [_btnLevel setImage:[UIImage imageNamed:@"原创达人"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@"原创达人"] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#8D6FFF" alpha:1.0] forState:0];
        } else if (level == 201){
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"4"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch] forState:0];
            [_btnLevel setImage:[UIImage imageNamed:@"专题小编"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@"专题小编"] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#8D6FFF" alpha:1.0] forState:0];
        }
    }
    
    else {
        //等级显示处理
        CGRect lf = _btnLevel.frame;
        [self autoWidthOfLabel:_labName with:21];
        lf.origin.x = CGRectGetMaxX(_labName.frame) + 5;
        lf.size.width = 46;
        _btnLevel.frame = lf;
        [_btnVip setFrame:CGRectMake(CGRectGetMaxX(lf) + 5, lf.origin.y - 2, 52, 18)];
        if (level >= 1 && level < 6){
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"1"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch] forState:0];
            [_btnLevel setImage:[UIImage imageNamed:@"Star 1"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@" Lv 0%@",topic.user_info.group_icon] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#A4A4A4" alpha:1.0] forState:0];
        } else if (level >= 6 && level < 11) {
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"2"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch]  forState:0 ];
            [_btnLevel setImage:[UIImage imageNamed:@"Star 2"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@" Lv %@",topic.user_info.group_icon] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#1BC156" alpha:1.0] forState:0];
        } else if (level >= 11 && level < 16) {
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"3"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch]  forState:0 ];
            [_btnLevel setImage:[UIImage imageNamed:@"Star 3"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@" Lv %@",topic.user_info.group_icon] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#4A90E2" alpha:1.0] forState:0];
        } else if (level >= 16 && level < 21) {
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"4"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch]  forState:0 ];
            [_btnLevel setImage:[UIImage imageNamed:@"Star 4"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@" Lv %@",topic.user_info.group_icon] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#8D6FFF" alpha:1.0] forState:0];
        } else if (level >= 21 && level < 26) {
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"5"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch]   forState:0 ];
            [_btnLevel setImage:[UIImage imageNamed:@"Star 5"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@" Lv %@",topic.user_info.group_icon] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#FF9300" alpha:1.0] forState:0];
        } else if (level >= 26 && level < 31) {
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"5"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch]   forState:0 ];
            [_btnLevel setImage:[UIImage imageNamed:@"Star 6"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@" Lv %@",topic.user_info.group_icon] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#FF9300" alpha:1.0] forState:0];
        } else if (level >= 31 && level < 36) {
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"7"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch]   forState:0 ];
            [_btnLevel setImage:[UIImage imageNamed:@"Star 7"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@" Lv %@",topic.user_info.group_icon] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#FF70A6" alpha:1.0] forState:0];
        } else if (level >= 36 && level < 41) {
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"8"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch]   forState:0 ];
            [_btnLevel setImage:[UIImage imageNamed:@"Star 8"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@" Lv %@",topic.user_info.group_icon] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#3785FF" alpha:1.0] forState:0];
        } else if (level >= 41 && level < 46) {
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"4"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch]   forState:0 ];
            [_btnLevel setImage:[UIImage imageNamed:@"Star 9"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@" Lv %@",topic.user_info.group_icon] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#962BFF" alpha:1.0] forState:0];
        } else if (level >= 46 && level < 51) {
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"10"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch]   forState:0 ];
            [_btnLevel setImage:[UIImage imageNamed:@"Star 10"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@" Lv %@",topic.user_info.group_icon] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#FFA52A" alpha:1.0] forState:0];
        } else if (level >= 51 && level < 56) {
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"11"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch]   forState:0 ];
            [_btnLevel setImage:[UIImage imageNamed:@"Star 11"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@" Lv %@",topic.user_info.group_icon] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#FF70A6" alpha:1.0] forState:0];
        } else if (level >= 56 && level < 100) {
            [_btnLevel setBackgroundImage:[[UIImage imageNamed:@"12"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,6,0,6) resizingMode:UIImageResizingModeStretch]  forState:0 ];
            [_btnLevel setImage:[UIImage imageNamed:@"Star 12"] forState:0];
            [_btnLevel setTitle:[NSString stringWithFormat:@" Lv %@",topic.user_info.group_icon] forState:0];
            [_btnLevel setTitleColor:[UIColor colorWithHexString:@"#FFFFFF" alpha:1.0] forState:0];
        }
    }
    
}

@end
